import java.util.Scanner;




//进制转换，考虑输入进制数0和负数的情况。
public class Text1 {
    public static char swap(int num) {
        switch (num) {
            case 10:
                return 'a';
            case 11:
                return 'b';
            case 12:
                return 'c';
            case 13:
                return 'd';
            case 14:
                return 'e';
            case 15:
                return 'f';
        }
        return (char)num;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//输入的十进制数
        int str = in.nextInt();
        int str1=str;
//需要转换的进制数
        int str2 = in.nextInt();
        StringBuffer str3 = new StringBuffer();
        if(str<0)
        {
            str=(-str);
        }
        int num = 0;
        if (str2 < 10) {
//当十进制数大于需要装换的进制数时
            while (str2 <= str) {
//字符串添加余数
                str3 .append(str % str2);
                str = str / str2;
            }
//将剩余的余数添加到字符串
            str3 .append(str) ;
        } else {
            while (str2 <= str) {
                num = str % str2;
                if (num >= 10) {
                    str3 .append(swap(num));
                } else str3 .append(num);
                str = str / str2;
            }
            num = str % str2;
            if (num >= 10) {
                str3 .append(swap(num));
            } else str3 .append(num);
        }
        if (str1 < 0) {
            System.out.printf(str3.append("-").reverse().toString());
        }
        else if(str1>0)
        {
            System.out.printf(str3.reverse().toString());
        }
        else
            System.out.printf("0");
    }
}
